<template>
	<view class="container">
		<view class="blue-background"></view>
		<!-- 主内容区域 -->
		<view class="main-content">
			<!-- 分段控制器 -->
			<view class="segment-control">
				<view class="segment-item" :class="{ active: currentTab === 'listed' }" @click="switchTab('listed')">
					已上架
				</view>
				<view class="segment-item" :class="{ active: currentTab === 'unlisted' }"
					@click="switchTab('unlisted')">
					未上架
				</view>
			</view>

			<!-- 分隔线 -->
			<view class="divider"></view>

			<!-- 活动列表 -->
			<view class="activity-list">
				<view class="activity-item" v-for="(item, index) in currentActivities" :key="index">
					<view class="activity-content">
						<view class="activity-title">{{ item.title }}</view>
						<!-- 未上架状态下显示审核状态 -->
						<view v-if="currentTab === 'unlisted'" class="activity-status" :class="item.statusClass">
							{{ item.status }}
						</view>
						<view class="activity-time">{{ item.time }}</view>
					</view>
					<view class="activity-action">
						<button class="action-btn" :class="item.btnClass" @click="handleAction(item, index)">
							{{ item.actionText }}
						</button>
					</view>
				</view>
			</view>
		</view>

		<!-- 底部发布按钮 -->
		<view class="publish-btn-container">
			<button class="publish-btn" @click="publishActivity">
				<text class="plus-icon">+</text>
				发布活动
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				currentTab: 'unlisted', // 默认显示未上架
				// 已上架活动数据
				listedActivities: [{
						title: '阳春三月油江南活动开始报名了',
						time: '2023-03-10 11:09',
						status: '已上架',
						actionText: '下架',
						btnClass: 'btn-take-down'
					},
					{
						title: '阳春三月油江南活动开始报名了',
						time: '2023-03-10 11:09',
						status: '已上架',
						actionText: '下架',
						btnClass: 'btn-take-down'
					}
				],
				// 未上架活动数据
				unlistedActivities: [{
						title: '阳春三月油江南活动开始报名了',
						time: '2023-03-10 11:09',
						status: '审核中',
						statusClass: 'status-reviewing',
						actionText: '删除',
						btnClass: 'btn-delete'
					},
					{
						title: '阳春三月油江南活动开始报名了',
						time: '2023-03-10 11:09',
						status: '审核成功',
						statusClass: 'status-success',
						actionText: '上架',
						btnClass: 'btn-publish'
					},
					{
						title: '阳春三月油江南活动开始报名了',
						time: '2023-03-10 11:09',
						status: '审核失败',
						statusClass: 'status-failed',
						actionText: '删除',
						btnClass: 'btn-delete'
					}
				]
			}
		},
		computed: {
			currentActivities() {
				return this.currentTab === 'listed' ? this.listedActivities : this.unlistedActivities;
			}
		},
		methods: {
			// 切换标签页
			switchTab(tab) {
				this.currentTab = tab;
			},
			// 处理操作按钮点击
			handleAction(item, index) {
				if (item.actionText === '删除') {
					this.deleteActivity(index);
				} else if (item.actionText === '上架') {
					this.publishToShelf(index);
				} else if (item.actionText === '下架') {
					this.takeDownFromShelf(index);
				}
			},
			// 删除活动
			deleteActivity(index) {
				uni.showModal({
					title: '确认删除',
					content: '确定要删除这个活动吗？',
					success: (res) => {
						if (res.confirm) {
							this.unlistedActivities.splice(index, 1);
							uni.showToast({
								title: '删除成功',
								icon: 'success'
							});
						}
					}
				});
			},
			// 上架活动
			publishToShelf(index) {
				const activity = this.unlistedActivities[index];
				this.listedActivities.push({
					...activity,
					status: '已上架',
					actionText: '下架',
					btnClass: 'btn-take-down'
				});
				this.unlistedActivities.splice(index, 1);
				uni.showToast({
					title: '上架成功',
					icon: 'success'
				});
			},
			// 下架活动
			takeDownFromShelf(index) {
				const activity = this.listedActivities[index];
				this.unlistedActivities.push({
					...activity,
					status: '已下架',
					statusClass: 'status-failed',
					actionText: '删除',
					btnClass: 'btn-delete'
				});
				this.listedActivities.splice(index, 1);
				uni.showToast({
					title: '下架成功',
					icon: 'success'
				});
			},
			// 发布新活动
			publishActivity() {
				uni.navigateTo({
					url: '/pages/activity/publish'
				});
			}
		}
	}
</script>

<style scoped>
	.container {
		background-color: #f5f5f5;
		min-height: 100vh;
		padding-bottom: 120rpx;
		position: relative;
	}

	.blue-background {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 300rpx;
		background: linear-gradient(120deg, #3385fd 0%, #3385fd 100%);
	}

	/* 主内容区域 */
	.main-content {
		position: absolute;
		left: 3%;
		right: 3%;
		top: 1rpx;
		z-index: 2;
		background-color: white;
		border-radius: 12rpx;
		overflow: hidden;
	}

	/* 分段控制器样式 */
	.segment-control {
		display: flex;
		margin: 42rpx 180rpx;
		background-color: #f0f0f0;
		border-radius: 50rpx;
		overflow: hidden;
		/* width: 360rpx; */
		width: 50%;
	}

	.segment-item {
		flex: 1;
		text-align: center;
		padding: 20rpx 0;
		font-size: 30rpx;
		color: #007AFF;
		background-color: #f0f0f0;
		transition: all 0.3s ease;
	}

	.segment-item.active {
		background-color: #007AFF;
		color: white;
	}

	/* 分隔线 */
	.divider {
		height: 5rpx;
		background-color: #F8F8F8;
		margin: 0 20rpx;
	}

	/* 活动列表样式 */
	.activity-list {
		padding: 0 20rpx 20rpx 20rpx;
	}

	.activity-item {
		padding: 30rpx 0;
		border-bottom: 1rpx solid #f0f0f0;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.activity-item:last-child {
		border-bottom: none;
	}

	.activity-content {
		flex: 1;
		text-align: left;
	}

	.activity-title {
		font-size: 32rpx;
		color: #333;
		margin-bottom: 8rpx;
		font-weight: 500;
		line-height: 1.4;
	}

	.activity-status {
		font-size: 24rpx;
		margin-bottom: 8rpx;
		font-weight: 500;
	}

	.status-reviewing {
		color: #ff0000;
	}

	.status-success {
		color: #34C759;
	}

	.status-failed {
		color: #999;
	}

	.activity-time {
		font-size: 24rpx;
		color: #999;
	}

	.activity-action {
		margin-left: 20rpx;
	}

	.action-btn {
		padding: 4rpx 48rpx;
		border-radius: 32rpx;
		font-size: 24rpx;
		border: none;
		color: white;
		min-width: 100rpx;
	}

	.btn-delete {
		background-color: #0055ff;
	}

	.btn-publish {
		background-color: #0055ff;
	}

	.btn-take-down {
		background-color: #0055ff;
	}

	/* 底部发布按钮样式 */
	.publish-btn-container {
		position: fixed;
		bottom: 70rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 70%;
	}

	.publish-btn {
		width: 100%;
		background-color: #007AFF;
		color: white;
		border: none;
		border-radius: 58rpx;
		padding: 2rpx 0;
		font-size: 32rpx;
		font-weight: 500;
		display: flex;
		align-items: center;
		justify-content: center;
		box-shadow: 0 4rpx 12rpx rgba(0, 122, 255, 0.3);
	}

	.plus-icon {
		font-size: 36rpx;
		margin-right: 10rpx;
		font-weight: bold;
	}
</style>